from jili.calc import calcor_base
class ror_byv2(calcor_base):
    def __init__(self,ta_arg={}):
        self.out = ["ror"]
        self.input = ["close","close"]
        self.parameters = {"timeperiod":1}
        super().__init__(ta_arg)
        self.batch=self.parameters["timeperiod"]+1
    def calc(self):
        data0=self.hisbars[self.input[0]]
        data1 = self.hisbars[self.input[1]]
        percentile = (data1[-1]-data0[0])/data0[0]
        return percentile
class ror_byv2_self(calcor_base):
    def __init__(self,ta_arg={}):
        self.out = ["ror"]
        self.input = ["close","close"]
        self.parameters = {"timeperiod":1,"function":[None,None]}
        super().__init__(ta_arg)
        self.batch=self.parameters["timeperiod"]+1
        self.func0=self.parameters["function"][0]#分母
        self.func1 = self.parameters["function"][1]#分子
    def calc(self):
        data0=self.hisbars[self.input[0]]
        data1 = self.hisbars[self.input[1]]
        if self.func0:
            a=self.func0(data0)
        else:
            a=data0[0]
        if self.func1:
            b=self.func1(data1)
        else:
            b=data1[-1]
        percentile = b/a-1
        return percentile
ror2=ror_byv2
ror2_self=ror_byv2_self
